<%@ Control Language="C#" AutoEventWireup="true"
	Inherits="System.Web.Mvc.ViewUserControl<gnodotnet.Web.Controllers.MailingList.MessagesController.MessageFormViewModel>" %>
<%@ Import Namespace="gnodotnet.Core.MailingList" %>
<%@ Import Namespace="gnodotnet.Web.Controllers" %>
<%@ Import Namespace="gnodotnet.Web.Controllers.MailingList" %> 

<% if (ViewContext.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] != null) { %>
    <p id="pageMessage"><%= ViewContext.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()]%></p>
<% } %>

<%= Html.ValidationSummary() %>

<% using (Html.BeginForm()) { %>
    <%= Html.AntiForgeryToken() %>
    <%= Html.Hidden("Message.Id", (ViewData.Model.Message != null) ? ViewData.Model.Message.Id : 0)%>

    <ul>
		<li>
			<label for="Message_Subject">Subject:</label>
			<div>
				<%= Html.TextBox("Message.Subject", 
					(ViewData.Model.Message != null) ? ViewData.Model.Message.Subject.ToString() : "")%>
			</div>
			<%= Html.ValidationMessage("Message.Subject")%>
		</li>
		<li>
			<label for="Message_Contents">Contents:</label>
			<div>
				<%= Html.TextArea("Message.Contents", ViewData.Model.Message.IfNotNull(x=>x.Contents, "")) %>
			</div>
			<%= Html.ValidationMessage("Message.Contents")%>
		</li>
		<li>
			<label for="Message_SentOn">SentOn:</label>
			<div>
				<%= ViewData.Model.Message.IfNotNull(x=>x.SentOn.ToString(), "") %>
			</div>
		</li>
	    <li>
            <%= Html.SubmitButton("btnSave", "Save Message") %>
	        <%= Html.Button("btnCancel", "Cancel", HtmlButtonType.Button, 
				    "window.location.href = '" + Html.BuildUrlFromExpression<MessagesController>(c => c.Index()) + "';") %>
        </li>
    </ul>
<% } %>
